/**
 * @author wangj881
 * @date 2025-03-11 17:21
 */
public class L226_3 {

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1);
        TreeNode treeNode3 = new TreeNode(3);
        TreeNode treeNode2 = new TreeNode(2, treeNode, treeNode3);
        TreeNode treeNode6 = new TreeNode(6);
        TreeNode treeNode9 = new TreeNode(9);
        TreeNode treeNode7 = new TreeNode(7, treeNode6, treeNode9);
        TreeNode treeNode4 = new TreeNode(4, treeNode2, treeNode7);

        new Solution().invertTree(treeNode4);

    }

    static class Solution {
        public TreeNode invertTree(TreeNode root) {

            fanzhuan(root);
            return root;

        }

        private void fanzhuan(TreeNode root) {
            if (null == root) {
                return;
            }
            fanzhuan(root.left);
            fanzhuan(root.right);

            TreeNode tmp = root.right;
            root.right = root.left;
            root.left = tmp;
        }
    }

}
